package com.scu.servlet;

import com.scu.dao.CommentDao;
import com.scu.entity.Comment;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "AddCommentServlet", value = "/AddCommentServlet")
public class AddCommentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String comment_id = request.getParameter("comment_id");
        String comment_content = request.getParameter("comment_content");
        String user_id = request.getParameter("user_id");
        String date = request.getParameter("date");

        String post_id = request.getParameter("post_id");


        Comment comment = new Comment();
        comment.setComment_id(Integer.parseInt(comment_id));
        comment.setComment_content(comment_content);
        comment.setUser_id(Integer.parseInt(user_id));
        comment.setDate(date);
        comment.setPost_id(Integer.parseInt(post_id));
        try {
            new CommentDao().insert(comment);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
